<?php
/**
 * Loop Add to Cart
 */

global $product;

if ( ! $product->is_purchasable() && $product->product_type != 'external' ) return;
?>

<?php if ( ! $product->is_in_stock() ) : ?>

	<a href="<?php echo apply_filters( 'out_of_stock_add_to_cart_url', get_permalink( $product->id ) ); ?>" class="button2"><?php echo apply_filters( 'out_of_stock_add_to_cart_text', __( 'Read More', 'qns' ) ); ?></a>

<?php else : ?>

	<?php

		switch ( $product->product_type ) {
			case "variable" :
				$link 	= apply_filters( 'variable_add_to_cart_url', get_permalink( $product->id ) );
				$label 	= apply_filters( 'variable_add_to_cart_text', __('Select options','qns' ) );
			break;
			case "grouped" :
				$link 	= apply_filters( 'grouped_add_to_cart_url', get_permalink( $product->id ) );
				$label 	= apply_filters( 'grouped_add_to_cart_text', __('View options','qns' ) );
			break;
			case "external" :
				$link 	= apply_filters( 'external_add_to_cart_url', get_permalink( $product->id ) );
				$label 	= apply_filters( 'external_add_to_cart_text', __('Read More','qns' ) );
			break;
			default :
				$link 	= apply_filters( 'add_to_cart_url', esc_url( $product->add_to_cart_url() ) );
				$label 	= apply_filters( 'add_to_cart_text', __('Add to cart','qns' ) );
			break;
		}

		printf('<p class="product-button clearfix"><a href="%s" rel="nofollow" data-product_id="%s" class="button2 product_type_%s">%s</a></p>', $link, $product->id, $product->product_type, $label);

	?>

<?php endif; ?>